use std::collections::HashMap;
pub fn convert_base(num_str: &str, to_base: u32) -> String {
    let mut input: i32 = 0;
    let mut map = HashMap::new();
    for c in '0'..='9' {
        let digit = c as i32 - '0' as i32;
        map.insert(c, digit);
    }
    for c in 'A'..='F' {
        let digit = 10 + c as i32 - 'A' as i32;
        map.insert(c, digit);
    }
    let mut number = 0;
    if let Some(start) = num_str.find('(') {
        if let Some(end) = num_str.find(')') {
            if end > start {
                let number_str = &num_str[start + 1..end];
                number = number_str.parse().unwrap();
            }
        }
    }

    for &byte in num_str.as_bytes() {
        if byte == b'(' {
            break;
        }
        input *= number;
        input += map[&(byte as char)];
    }

    let digits = "0123456789abcdef";

    if input == 0 {
        return String::from("0");
    }

    let mut result = String::new();

    while input > 0 {
        let remainder = (input % to_base as i32) as usize;
        result.push(digits.chars().nth(remainder).unwrap());
        input /= to_base as i32;
    }

    result.chars().rev().collect()
}
